    package cn.vendsystem.com.exception;


    import cn.vendcommon.com.entity.Result;
    import cn.vendcommon.com.exception.VendException;
    import jakarta.servlet.http.HttpServletResponse;
    import lombok.extern.slf4j.Slf4j;
    import org.springframework.web.bind.annotation.ControllerAdvice;
    import org.springframework.web.bind.annotation.ExceptionHandler;
    import org.springframework.web.bind.annotation.ResponseBody;

    @Slf4j
    @ControllerAdvice
    public class CommonControllerAdvice {

        @ExceptionHandler(value = VendException.class)
        @ResponseBody
        public Result exceptionHandler(VendException e, HttpServletResponse response) {
            log.warn("[业务异常],出现业务异常：{}", e.getMessage());
            response.setStatus(200); // ✅ 永远 200
            if (e.getCommonCodeMsg() != null) {
                return Result.errorCommonCode(e.getCommonCodeMsg());
            }
            return Result.error("未知错误");
        }

        @ExceptionHandler(value = Exception.class)
        @ResponseBody
        public Result exceptionHandler(Exception e) {
            log.warn("[通用系统异常],出现系统异常：{}",e.getMessage());
            return Result.error(e.getMessage());
        }
    }
